package presentation.playgameForm_UI;

import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JWindow;

import presentation.menuForm_UI.Picture;

@SuppressWarnings("serial")
public class EndGame_UI extends JWindow {

	private JLabel	lblWordFound	= new JLabel("Word Found: ");
	private JLabel	lblBestWord		= new JLabel("Best Word	: ");
	private JLabel	lblBestMove		= new JLabel("Best Move	: ");
	private JLabel	lblScore		= new JLabel("Score		: ");
	private JLabel	lblMaxLevel		= new JLabel("Max Level	: ");
	private JLabel	lblTimePlay		= new JLabel("Time Play	: ");
	
	private JLabel	lbrWordFound	= new JLabel("WORDFOUND", JLabel.LEFT);
	private JLabel	lbrBestWord		= new JLabel("INTERNATIONALLY", JLabel.LEFT);
	private JLabel	lbrBestMove		= new JLabel("BESTMOVE", JLabel.LEFT);
	private JLabel	lbrScore		= new JLabel("SCORE", JLabel.LEFT);
	private JLabel	lbrMaxLevel		= new JLabel("MAXLEVEL", JLabel.LEFT);
	private JLabel	lbrTimePlay		= new JLabel("TIMEPLAY", JLabel.LEFT);
	
	private JButton btnBack = new JButton("Back to main menu");
	
	private Picture panelInfo = new Picture();
	private JPanel panelButton = new JPanel(null);
	
	private JDialog dlg;

	public EndGame_UI(JDialog dlg) {
		super(dlg);
		this.dlg = dlg;
		initComponents();
		
		this.setOpacity(0.9f);
		this.setSize(380, 280);
		this.setAlwaysOnTop(true);
		this.setLocationRelativeTo(dlg);
		this.requestFocus();
	}
	
	private void initComponents()
	{
		setLabelProperties();
		setButtonProperties();
		
		setMainLayout();
		setPanelInfoLayout();
		setPanelButtonLayout();
		
		buttonEvent();
		windowEvent();
	}
	
	private void setLabelProperties()
	{
		lblWordFound.setFont(new Font("Courier New", 0, 16));
		lblBestWord.setFont(lblWordFound.getFont());	
		lblBestMove.setFont(lblWordFound.getFont());
		lblScore.setFont(lblWordFound.getFont());
		lblMaxLevel.setFont(lblWordFound.getFont());
		lblTimePlay.setFont(lblWordFound.getFont());
		
		lbrWordFound.setFont(lblWordFound.getFont());
		lbrBestWord.setFont(lblWordFound.getFont());	
		lbrBestMove.setFont(lblWordFound.getFont());
		lbrScore.setFont(lblWordFound.getFont());
		lbrMaxLevel.setFont(lblWordFound.getFont());
		lbrTimePlay.setFont(lblWordFound.getFont());
	}
	
	private void setButtonProperties()
	{
		btnBack.setFont(lblWordFound.getFont());
	}
	
	private void setMainLayout()
	{
		this.setLayout(null);
		this.add(panelInfo);
		this.add(panelButton);
		
		panelInfo.setBounds(0, 0, 380, 240);
		panelButton.setBounds(panelInfo.getX(), panelInfo.getY() + panelInfo.getHeight(), panelInfo.getWidth(), 40);
		
//		panelInfo.setBackground(new Color(255, 255, 255));
		panelButton.setBackground(new Color(232, 232, 232));
		panelInfo.setBackground(new Color(232, 232, 232));
		this.getContentPane().setBackground(new Color(232, 232, 232));
	}
	
	private void setPanelInfoLayout()
	{
		panelInfo.setLayout(null);
		panelInfo.path = "src/image/tooltips/EndGame.png";
		panelInfo.repaint();
		
		panelInfo.add(lblBestMove);
		panelInfo.add(lblBestWord);
		panelInfo.add(lblMaxLevel);
		panelInfo.add(lblScore);
		panelInfo.add(lblTimePlay);
		panelInfo.add(lblWordFound);
		
		panelInfo.add(lbrBestMove);
		panelInfo.add(lbrBestWord);
		panelInfo.add(lbrMaxLevel);
		panelInfo.add(lbrScore);
		panelInfo.add(lbrTimePlay);
		panelInfo.add(lbrWordFound);
		
		lblWordFound.setBounds(60, 30, 120, 30);
		lblBestWord.setBounds(lblWordFound.getX(), lblWordFound.getY() + lblWordFound.getHeight(), lblWordFound.getWidth(), lblWordFound.getHeight());
		lblBestMove.setBounds(lblWordFound.getX(), lblBestWord.getY() + lblWordFound.getHeight(), lblWordFound.getWidth(), lblWordFound.getHeight());
		lblScore.setBounds(lblWordFound.getX(), lblBestMove.getY() + lblWordFound.getHeight(), lblWordFound.getWidth(), lblWordFound.getHeight());
		lblMaxLevel.setBounds(lblWordFound.getX(), lblScore.getY() + lblWordFound.getHeight(), lblWordFound.getWidth(), lblWordFound.getHeight());
		lblTimePlay.setBounds(lblWordFound.getX(), lblMaxLevel.getY() + lblWordFound.getHeight(), lblWordFound.getWidth(), lblWordFound.getHeight());
		
		lbrWordFound.setBounds(lblWordFound.getX() + lblWordFound.getWidth() + 10, lblWordFound.getY(), lblWordFound.getWidth()+50, lblWordFound.getHeight());
		lbrBestWord.setBounds(lblWordFound.getX() + lblWordFound.getWidth() + 10, lblBestWord.getY(), lbrWordFound.getWidth(), lblWordFound.getHeight());
		lbrBestMove.setBounds(lblWordFound.getX() + lblWordFound.getWidth() + 10, lblBestMove.getY(), lbrWordFound.getWidth(), lblWordFound.getHeight());
		lbrScore.setBounds(lblWordFound.getX() + lblWordFound.getWidth() + 10, lblScore.getY(), lbrWordFound.getWidth(), lblWordFound.getHeight());
		lbrMaxLevel.setBounds(lblWordFound.getX() + lblWordFound.getWidth() + 10, lblMaxLevel.getY(), lbrWordFound.getWidth(), lblWordFound.getHeight());
		lbrTimePlay.setBounds(lblWordFound.getX() + lblWordFound.getWidth() + 10, lblTimePlay.getY(), lbrWordFound.getWidth(), lblWordFound.getHeight());
	}
	
	private void setPanelButtonLayout()
	{
		panelButton.add(btnBack);
		btnBack.setBounds(0, 0, panelButton.getWidth(), panelButton.getHeight());
	}
	
	private void buttonEvent()
	{
		btnBack.addActionListener(new ActionListener()
		{
			@Override
			public void actionPerformed(ActionEvent evt)
			{
				dlg.dispose();
				dispose();
			}
		});
	}
	
	private void windowEvent()
	{
		this.addWindowFocusListener(new WindowAdapter() 
		{
			@Override
			public void windowClosing(WindowEvent evt)
			{
			}
			@Override
			public void windowClosed(WindowEvent evt)
			{
			}
		});
	}
	
	public void setLabelValue(int wordFound, String bestWord, int bestMove, int score, int maxLevel, String timePlay)
	{
		lbrWordFound.setText(wordFound + "");
		lbrBestWord.setText(bestWord);
		lbrBestMove.setText(bestMove + "");
		lbrScore.setText(score + "");
		lbrMaxLevel.setText( maxLevel + "");
		lbrTimePlay.setText(timePlay);
	}

}